package com.dykj.dati.controller.h5;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dykj.dati.model.imp.Da;
import com.dykj.dati.model.t.TKuDa;
import com.dykj.dati.model.t.TKuTitle;
import com.dykj.dati.service.t.ITKuDaService;
import com.dykj.dati.service.t.ITKuTitleService;
import com.dykj.dati.utils.ReturnUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/test")
public class TestController {
    @Autowired
    private ITKuDaService tKuDaService;

    @Autowired
    private ITKuTitleService     tKuTitleService;

    @GetMapping("/imp")
    @ResponseBody
    public ModelMap list() throws Exception {
        ImportParams params = new ImportParams();
        params.setTitleRows(0);
        List<Da> daList= ExcelImportUtil.importExcel(FileUtil.getInputStream(FileUtil.file("d:\\dt.xls")), Da.class, params);
        List<TKuTitle> tKuTitleList=new ArrayList<>();
        List<TKuDa> tKuDaList=new ArrayList<>();
        for(Da da : daList){
            String id= IdUtil.simpleUUID();
            Date date= DateUtil.date();
            TKuTitle tKuTitle=new TKuTitle();
            tKuTitle.setId(id);
            tKuTitle.setCreateTime(date);
            tKuTitle.setTitle(da.getTm());
            tKuTitle.setZq(da.getZq());
            tKuTitleList.add(tKuTitle);

            TKuDa tKuDaa=new TKuDa();
            tKuDaa.setId(IdUtil.simpleUUID());
            tKuDaa.setCreateTime(DateUtil.date());
            tKuDaa.setTId(id);
            tKuDaa.setK("A");
            tKuDaa.setDa(da.getXxa());

            TKuDa tKuDab=new TKuDa();
            tKuDab.setId(IdUtil.simpleUUID());
            tKuDab.setCreateTime(DateUtil.date());
            tKuDab.setTId(id);
            tKuDab.setK("B");
            tKuDab.setDa(da.getXxb());

            TKuDa tKuDaC=new TKuDa();
            tKuDaC.setId(IdUtil.simpleUUID());
            tKuDaC.setCreateTime(DateUtil.date());
            tKuDaC.setTId(id);
            tKuDaC.setK("C");
            tKuDaC.setDa(da.getXxc());


            tKuDaList.add(tKuDaa);
            tKuDaList.add(tKuDab);
            tKuDaList.add(tKuDaC);


        }
        tKuDaService.saveBatch(tKuDaList);
        tKuTitleService.saveBatch(tKuTitleList);
        return ReturnUtil.Success("成功！");
    }

}
